package cn.fruitmarket;
import cn.fruitmarket.goods.Fruit;
import cn.fruitmarket.sellstrategy.RebateStrategy;
import cn.fruitmarket.sellstrategy.ReduceStrategy;
import cn.fruitmarket.shopcar.CarItem;
import cn.fruitmarket.shopcar.ShoppingCar;
import cn.fruitmarket.utils.MoneyUtil;

import java.util.Date;

public class MarketClientApp {

    public static void main(String[] args) throws Exception {
        ShoppingCar car  = new ShoppingCar();
        car.setCreateDate(new Date()); //设置购物车创建时间
        //添加苹果
        Fruit apple = new Fruit("apple",8);
        CarItem appleItem = new CarItem(apple,10);
        car.addItem(appleItem);

        //添加草莓
        Fruit strawberry = new Fruit("strawberry",13);
        CarItem strawberryItem = new CarItem(strawberry,10);
        RebateStrategy rebateStrategy=new RebateStrategy("2023-02-09 09:00","2023-03-01 18:00",0.8);
        strawberryItem.addStragegys(rebateStrategy);//添加限时促销
        car.addItem(strawberryItem);

        //添加芒果
        Fruit mango = new Fruit("mango",20);
        car.addItem(new CarItem(mango,10));

        //添加总金额促销策略
        ReduceStrategy reduceStrategy = new ReduceStrategy("2023-02-09 09:00","2023-03-01 18:00",100,10);
        car.addStragegys(reduceStrategy);
        //结算
        car.accounting();
        //输出
        double amount = car.getAmount();
        String result = MoneyUtil.formatMoney(MoneyUtil.roudTwo(amount)+"");
        System.out.println("总价 = "+ result);
    }
}
